package com.dsr.controller;

import com.dsr.consts.Result;
import com.dsr.entity.Flower;
import com.dsr.service.FlowerService;
import com.dsr.util.BasicUtil;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;


/**
 * (Flower)表控制层
 *
 * @author dsr
 * @since 2020-08-16
 */
@Api(tags = "(Flower)表控制层")
@RestController
@RequestMapping("/flower")
public class FlowerController {

    @Autowired
    private FlowerService flowerService;

    @ApiOperation("更具id获取实体")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "id", value = "id", required = true)
    })
    @GetMapping("/get/{id}")

    public Result getEntity(@PathVariable String id) {
//        String remoteAddr = request.getRemoteAddr();
//        System.out.print(remoteAddr);

        System.out.println(BasicUtil.getToken("id"));
        return flowerService.getEntity(id);
    }

    @ApiOperation("保存操作")
    @ApiParam(name = "flower", value = "实体", required = true)
    @PostMapping("/save")
    public Result save(@RequestBody Flower flower) {
        return flowerService.save(flower);
    }

    @ApiOperation("更新操作")
    @ApiParam(name = "flower", value = "实体", required = true)
    @PutMapping("/update")
    public Result update(@RequestBody Flower flower) {
        return flowerService.update(flower);
    }

    @ApiOperation("根据id删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id(ps:1,2,3)", required = true)
    })
    @DeleteMapping("/delete")
    public Result delete(@RequestBody String id) {
        return flowerService.delete(id);
    }

    @ApiOperation("查询接口")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "page", value = "页", required = true),
            @ApiImplicitParam(paramType = "path", name = "size", value = "每页大小", required = true),
    })
    @ApiParam(name = "flower", value = "查询字段", required = true)
    @PostMapping("/list/{page}/{size}")
    public Result query(@PathVariable int page, @PathVariable int size, @RequestBody Flower flower) {
        return flowerService.query(page, size, flower);
    }

    @ApiOperation("返回所有")
    @GetMapping("/list")
    public Result list() {
        return flowerService.list();
    }


}